package com.sc.byahi.user.client.components.maps;

import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.Widget;

public class MapWidget extends Widget {

	protected MapImpl impl;

	public static MapWidget getInstance(MapImpl impl) {
		if (impl == null) {
			return null;
		}
		return new MapWidget(impl);
	}

	public MapWidget(MapOptions options) {
		Element div = DOM.createDiv();
		setElement(div);
		impl = MapImpl.newInstance(div, options);
	}

	private MapWidget(MapImpl impl) {
		this.impl = impl;
		setElement(impl.getDiv());
	}

	public MapImpl getJso() {
		return impl;
	}

	/**
	 * Has to be called to resize the map if the canvas has changed.
	 */
	public final void triggerResize() {
		final LatLng center = impl.getCenter();
		impl.triggerResize();
		impl.setCenter(center);
	}

}
